package com.anli.Controller;

import com.anli.Service.DeptService;
import com.anli.pojo.Dept;
import com.anli.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;
    @GetMapping
    public Result dept() {
        log.info("查询全部数据");
        List<Dept> deptList= deptService.list();
        return Result.success(deptList);
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("删除部门的id:" + id);
        deptService.deleteById(id);
        return Result.success();
    }
    @PostMapping
    public Result add(@RequestBody Dept dept) {
        log.info("新增部门:" + dept);
        deptService.add(dept);
        return Result.success();
    }
    @PutMapping("/test")
    public Result update(@RequestBody Dept dept) {
        log.info("修改部门"+dept);
        deptService.update(dept);
        return Result.success();
    }

}
